package com.dq.ad;

import android.util.Log;


/**
 * FileName: JLUtils
 * Author: admin
 * Date: 2021/12/23 10:36
 * Description:
 */
public class JLUtils {

    public static String TAG = JLUtils.class.getSimpleName();
    public static int PLATFORM_TT = 3;
    public static int PLATFORM_GRO_MORE = 17;

    public static boolean isBrShowNum = false;
    public static boolean isBrClickNum = false;
    public static boolean isBrLowPrice = false;
    public static int platform = -1;
    public static int targetPlatform = PLATFORM_GRO_MORE;

    private static boolean isUpload = true;

//    public static void setBehaviorRecord(BehaviorRecord br) {
//        if (isUpload) {
//            if (br != null) {
//                Log.e(TAG, br.toString());
//                isBrShowNum = br.getSnt() == 1;
//                isBrClickNum = br.getCnt() == 1;
//                isBrLowPrice = br.getLpt() == 1;
//            } else {
//                Log.i(TAG, "br == null");
//            }
//        }
//    }

    public static void setTargetPlatform(int platform) {
        if (isUpload) {
            targetPlatform = platform;
        }
    }

    public static int getTargetPlatform() {
        return targetPlatform;
    }

    public static void setPlatform(int pf) {
        if (isUpload) {
            platform = pf;
        }
    }

    public static boolean isTargetPlatform() {
        return targetPlatform == platform;
    }

    public static boolean isGroMore() {
        return PLATFORM_GRO_MORE == platform;
    }

    public static void jlShowCallback(boolean isSplash, double ecpm) {
        if (isUpload) {
            if (targetPlatform != platform) {
                Log.i(TAG, "not target platform : " + platform);
                return;
            }
            int lowPrice = 0;
            if (isBrLowPrice && isSplash) {
                lowPrice = 1;
            }
            int ecpmInt = (int) ecpm;
            if (isBrShowNum) {
                jlCallback(1, 0, lowPrice, ecpmInt);
            } else {
                Log.i(TAG, "isBrShowNum == false");
            }
        }
    }

    public static void jlClickCallback() {
        if (isUpload) {
            if (targetPlatform != platform) {
                Log.i(TAG, "not target platform : " + platform);
                return;
            }
            if (isBrClickNum) {
                jlCallback(0, 1, 0, 0);
            } else {
                Log.i(TAG, "isBrClickNum == false");
            }
        }
    }

    /**
     * 关键行为调用
     *
     * @param cstr
     * @param casr
     */
    public static void eventCallBack(String cstr, String casr) {
//        if (isUpload) {
//            Log.i(TAG, "上传关键行为：" + cstr + "," + casr);
//            HXCurrencySDK.getInstance()
//                    .jlCallbackTask(
//                            0,
//                            0,
//                            0,
//                            0, cstr, casr,
//                            new HttpUtil.HttpUtilCallback() {
//                                @Override
//                                public void onSuccess(int i, String s) {
//                                    Log.i(TAG, "关键行为回调上传成功:" + s);
//                                }
//
//                                @Override
//                                public void onFailed(int i, Throwable throwable) {
//                                    Log.i(TAG, "关键行为调用异常:" + throwable.getMessage());
//                                }
//                            });
//        }
    }

    /**
     * 广告回调调用
     *
     * @param showNum
     * @param clickNum
     * @param lowPrice
     * @param ecpm
     */
    private static void jlCallback(int showNum, int clickNum, int lowPrice, int ecpm) {
//        if (isUpload) {
//            Log.i(TAG, "开始上传广告回调");
//            HXCurrencySDK.getInstance()
//                    .jlCallbackTask(
//                            showNum,
//                            clickNum,
//                            lowPrice,
//                            ecpm, "", "",
//                            new HttpUtil.HttpUtilCallback() {
//                                @Override
//                                public void onSuccess(int i, String s) {
//                                    Log.i(TAG, "广告回调调用成功:" + s);
//                                }
//
//                                @Override
//                                public void onFailed(int i, Throwable throwable) {
//                                    Log.i(TAG, "广告回调调用异常:" + throwable.getMessage());
//                                }
//                            });
//        }
    }
}